package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.DamageGoodDao;
import com.atguigu.jxc.entity.*;
import com.atguigu.jxc.service.DamageGoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DamageGoodServiceImp implements DamageGoodService {
    @Autowired
    private DamageGoodDao damageGoodDao;
    @Transactional
    @Override
    public void save(DamageList damageList, List<DamageListGoods> damageListGoodsStr) {
        // 保存信息到 报损表中
        damageGoodDao.saveDamageList(damageList);
        damageListGoodsStr.stream().forEach(damageGood->{
            damageGood.setDamageListId(damageList.getDamageListId());
        });
        // 保存 信息到 报损明细表中
        damageGoodDao.saveDamageListGoods(damageListGoodsStr);
    }

    @Override
    public void saveOverflowListGoods(OverflowList overflowList, ArrayList<OverflowListGoods> list) {
        // 保存信息 到 过溢表中
        damageGoodDao.saveOverflowList(overflowList);
       /* [{"goodsId":1,"goodsTypeId":10,"goodsCode":"0001","goodsName":"陶华碧老干妈香辣脆油辣椒","goodsModel":"红色装"
                ,"goodsUnit":"瓶","lastPurchasingPrice":8.5,"price":"8.5","goodsNum":"1","total":8.5}]
        private Integer overflowListGoodsId;
        private Integer goodsId;
        private String goodsCode;
        private String goodsName;
        private String goodsModel;
        private String goodsUnit;
        private Integer goodsNum;
        private double price;
        private double total;
        private Integer overflowListId;
        private Integer goodsTypeId*/
        //保存 过溢商品信息到 明细表中
        list.stream().forEach(overflowListGoods -> {
            overflowListGoods.setOverflowListId(overflowList.getOverflowListId());
        });
        damageGoodDao.saveOverflowListGoods(list);
    }
  // 获取报损单 信息
    @Override
    public Map<String, Object> getDamageList(String sTime, String eTime) {
        HashMap<String, Object> map = new HashMap<>();
        List<DamageList> list = damageGoodDao.getDamageList(sTime,eTime);
        map.put("rows",list);
        return map;
    }
  //获取报损的 单中的 商品信息
    @Override
    public Map<String, Object> getDamageListGoods(Integer damageListId) {
        HashMap<String, Object> map = new HashMap<>();
        List<DamageListGoods> list  = damageGoodDao.getDamageListGoods(damageListId);
        map.put("rows",list);
        return map;
    }
    //获取 报溢单 信息
    @Override
    public Map<String, Object> getoverflowList(String sTime, String eTime) {
        HashMap<String, Object> map = new HashMap<>();
        List<DamageList> list = damageGoodDao.getoverflowList(sTime,eTime);
        map.put("rows",list);
        return map;
    }
  // 获取 报溢单中的商品信息
    @Override
    public Map<String, Object> getoverflowListGoods(Integer overflowListId) {
        HashMap<String, Object> map = new HashMap<>();
        List<DamageListGoods> list  = damageGoodDao.getoverflowListGoods(overflowListId);
        map.put("rows",list);
        return map;
    }


}
